﻿@model MongoDbHelper.Models.HomeIndexModel
@{
    ViewBag.Title = "MongoDB Helpers";
}
<div class="container-flui">
    <div class="row-fluid">
        <table class="table table-hover table-striped table-condensed">
            <thead>
                <tr>
                    <th>
                        ObjectId
                    </th>
                    <th>
                        Creation timestamp
                    </th>
                    <th>
                        Timestamp
                    </th>
                    <th>
                        Machine
                    </th>
                    <th>
                        Pid
                    </th>
                    <th>
                        Increment
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var line in Model.ObjectIds)
                {
                    var classText = line.Valid ? "" : "error";
                    <tr class="@classText">
                        <td>
                            @line.ObjectIdText
                        </td>
                        <td>
                            @line.CreationDateTimeText
                        </td>
                        <td>
                            @line.Timestamp
                        </td>
                        <td>
                            @line.Machine
                        </td>
                        <td>
                            @line.Pid
                        </td>
                        <td>
                            @line.Increment
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="row-fluid">
        <p>Paste a list of objectIds here, one per line:</p>
        <ul class="unstyled">
            <li>
                <textarea cols="26" rows="10" id="objectIds">@Model.ObjectIdText</textarea>
            </li>
            <li>
                <input id="parse" class="btn btn-primary" type="button" value="Parse" />        
            </li>
        </ul>
    </div>
</div>

@section scripts
{
    <script type="text/javascript">
        var baseUrl = "@Url.Action("Index")";

        $(document).ready(function () {
            $('#parse').click(parseClick);
        });
        
        function parseClick() {
            var objectIdsText = $('#objectIds').val();

            var lines = objectIdsText.split('\n');

            var newUrl = baseUrl + "?objectIds=" + lines.join();
            
            window.location = newUrl;
        }
    </script>
}
